package com.boge.study.design_pattern.proxy.jdk_proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * jdk动态代理，不需要为其他类型的交通工具重新写时间代理
 * @author Administrator
 *
 */
public class TimeHandler implements InvocationHandler {
	
	Object target;
	
	public TimeHandler(Object target) {
		super();
		this.target = target;
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		long startTime = System.currentTimeMillis();
		System.out.println("开始行驶...");
		method.invoke(target);
		long endTime = System.currentTimeMillis();
		System.out.println("结束行驶，行驶了" + (endTime - startTime) + "毫秒");
		return null;
	}

}
